package org.az.netty_study.p14_netty综合案例2_聊天室.server.handler;

import io.netty.channel.*;
import lombok.extern.slf4j.Slf4j;
import org.az.netty_study.p14_netty综合案例2_聊天室.server.session.SessionFactory;

@ChannelHandler.Sharable
@Slf4j
public class QuitRequestMessageHandler extends ChannelInboundHandlerAdapter {
    //连接断开触发的事件
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        SessionFactory.getSession().unbind(ctx.channel());
        log.info("{}已断开", ctx.channel());
    }

    //发生异常的事件
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        SessionFactory.getSession().unbind(ctx.channel());
        log.info("{}异常断开:{}", ctx.channel(), cause);
    }
}
